package ShuZu;

public class Homework {
    public static void main(String[] args) {


        //        1、定义一个整型数组
//        int[] numbers = {5, 15, 25, 35, 45};，编写代码计算并输出该数组中元素的个数
        int[] numbers = {5, 15, 25, 35, 45};
        int num = numbers.length;
        System.out.println(num);


        //        2、给定两个整数变量
//        int a = 10; int b = 20;，使用if语句找出并打印这两个数中的较大值
        int a = 10;
        int b = 20;
        if (a > b) {
            System.out.println(a);
        } else {
            System.out.println(b);
        }


        //        3、创建一个整型数组
//        int[] scores = {95, 85, 76, 88, 92};，使用for循环遍历数组，并计算所有成绩的总和后输出
        int[] scores = {95, 85, 76, 88, 92};
        int sum = 0;
        for (int nums : scores) {
            sum = nums + sum;
        }
        System.out.println(sum);


        //        4、定义两个布尔变量
//        boolean isSunny = true; boolean isWarm = false;，编写程序判断如果天气既晴朗(
//        isSunny)又温暖(isWarm)时，输出“Great weather for an outing!”
        String weather = "sunny";
        boolean isSunny = true;
        boolean isWarm = false;

        if (isSunny && isWarm) {
            System.out.println("Great weather for an outing!");
        } else {
            System.out.println("no outging!");
        }


        //        5、定义一个整型数组
//        int[] temperatures = {30, 22, 35, 18, 40};使用for循环遍历数组，并找到其中的最小值打印出来
        int[] temperatures = {30, 22, 35, 18, 40};
        int max = temperatures[0];
        int min = temperatures[0];
        for (int i = 0; i < temperatures.length; i++) {
            if (max < temperatures[i]) {
                max = temperatures[i];
            }
            if (min > temperatures[i]) {
                min = temperatures[i];
            }
        }
        System.out.println("max= " + max);
        System.out.println("min= " + min);
    }
}
